package com.wc.算法基础课.E第五讲动态规划.数位统计DP.数字游戏II;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/18 17:08
 * @description https://www.lanqiao.cn/problems/2956/learning/?page=1&first_category_id=1
 */
public class Main {
    static int N = 1010;
    static int M = 110;
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    // f[i][j][k] 表示有i位数第i数上为j的余数为k的个数
    static long[][][] f = new long[N][10][M];
    static String l, n;
    static int P;
    static int[] nums = new int[N];
    static int MOD = 998244353;

    public static void main(String[] args) {

        n = sc.next();
        P = sc.nextInt();
        init();
        out.println(dp(n) - dp("0"));
        out.flush();
    }

    static void init() {
//        for (int i = 0; i < N; i++) {
//            for (int j = 0; j <= 9; j++) {
//                for (int k = 0; k < M; k++) {
//                    f[i][j][k] = 0;
//                }
//            }
//        }
        for (int i = 0; i <= 9; i++) f[1][i][i % P]++;
        for (int i = 2; i < N; i++) {
            for (int j = 0; j <= 9; j++) {
                for (int k = 0; k <= P; k++) {
                    for (int x = 0; x <= 9; x++) {
                        f[i][j][k] = (f[i][j][k] + f[i - 1][x][mod(k - j, P)]) % MOD;
                    }
                }
            }
        }
    }

    static int mod(int x, int y) {
        return (x % y + y) % y;
    }

    // 0 ~ n 满足要求的
    static long dp(String n) {
        if (n.equals("0")) return 1;
        int len = n.length();
        for (int i = 0; i < len; i++) {
            nums[len - i - 1] = n.charAt(i) - '0';
        }
        long res = 0;
        int last = 0;
        for (int i = len - 1; i >= 0; i--) {
            int x = nums[i];
            for (int j = 0; j < x; j++) {
                res = (res + f[i + 1][j][mod(-last, P)]) % MOD;
            }
            last += x;
            if (i == 0 && last % P == 0) res = (res + 1) % MOD;
        }

        return res % MOD;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}